class SearchHour < Search
  # Make pluralize method available inside the model
  include ActionView::Helpers::TextHelper
  
  def initialize(user, params)
    super(user, params)
  end
  
  def search(options = {})
    unless p["project_id"] == ""
      find_by_date_and_project(options)
    else
      find_by_date(options)
    end
  end
  
  def info(found)
    "Hi, we found #{pluralize(found, 'hour')}"
  end
  
  private
  
  def find_by_date_and_project(options = {})
    user.hours.find_all_by_date_and_project_id(start_date..end_date, p["project_id"], options)
  end
  
  def find_by_date(options = {})
    user.hours.find_all_by_date(start_date..end_date, options)
  end
end